package com.yicong.taxi.base;

import android.app.Activity;

import com.kaopiz.kprogresshud.KProgressHUD;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;

/**
 * 基础presenter
 * Created by xybcoder on 2016/3/1.
 */
public class BaseActivityPresenter<T extends BaseView> {

  protected LifecycleProvider<ActivityEvent> provider;
  protected Activity activity;
  protected T iView;

  private KProgressHUD mProgressHUD;

  public BaseActivityPresenter(Activity activity, T iView,
                               LifecycleProvider<ActivityEvent> provider) {
    this.activity = activity;
    this.iView = iView;
    this.provider = provider;
  }

  public void init() {
    iView.initView();
  }

  //显示加载框
  public void showLoadingProgress(final String label) {
    activity.runOnUiThread(() -> mProgressHUD = KProgressHUD.create(activity)
            .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
            .setLabel(label)
            //.setCancellable(false)//点击返架取消
            .setGraceTime(500)
            .setSize(120, 110)
            .show());
  }

  //关闭加载框
  public void closeLoadingProgress() {
    activity.runOnUiThread(() -> {
      if (mProgressHUD != null) {
        mProgressHUD.dismiss();
      }
    });
  }

 protected void onDestory(){
    if(iView!=null){
      iView=null;
      System.gc();
    }
 }
}
